package com.syg.logback.core;

import com.syg.boot.util.time.DateUtil;
import com.syg.logback.consts.FileBizTypeEnum;
import com.syg.logback.consts.FileExeTypeEnum;
import org.apache.commons.lang3.StringUtils;

import java.io.Serializable;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.Date;

/**
 * @author syg
 * @version 1.0
 * @date 2021年11月24日19:14:46
 */
public class FileMonitorBuilder implements Serializable {
    private static final long serialVersionUID = 1L;
    private String flowId;
    private String bizNo;
    private String bizType;
    private String fileNo;
    private String fileTitle;
    private String fileName;
    private Long fileSize;
    private Long fileDataRow;
    private String exeType;
    private String startTime;
    private String endTime;
    private Integer exeTm;
    private String exeSts = "S";
    private String description;

    public FileMonitorBuilder() {
    }

    public FileMonitorBuilder setFlowId(String flowId) {
        if (StringUtils.isBlank(flowId)) {
            flowId = null;
        }

        this.flowId = flowId;
        return this;
    }

    public FileMonitorBuilder setBizNo(String bizNo) {
        if (StringUtils.isBlank(bizNo)) {
            bizNo = null;
        }

        this.bizNo = bizNo;
        return this;
    }

    public FileMonitorBuilder setBizType(FileBizTypeEnum fileBizTypeEnum) {
        this.bizType = fileBizTypeEnum.getCode();
        return this;
    }

    public FileMonitorBuilder setFileNo(String fileNo) {
        if (StringUtils.isBlank(fileNo)) {
            fileNo = null;
        }

        this.fileNo = fileNo;
        return this;
    }

    public FileMonitorBuilder setFileTitle(String fileTitle) {
        if (StringUtils.isBlank(fileTitle)) {
            fileTitle = null;
        }

        this.fileTitle = fileTitle;
        return this;
    }

    public FileMonitorBuilder setFileName(String fileName) {
        if (StringUtils.isBlank(fileName)) {
            fileName = null;
        }

        this.fileName = fileName;
        return this;
    }

    public FileMonitorBuilder setFileSize(Long fileSize) {
        this.fileSize = fileSize;
        return this;
    }

    public FileMonitorBuilder setFileDataRow(Long fileDataRow) {
        this.fileDataRow = fileDataRow;
        return this;
    }

    public FileMonitorBuilder setExeType(FileExeTypeEnum fileExeTypeEnum) {
        this.exeType = fileExeTypeEnum.getCode();
        return this;
    }

    public FileMonitorBuilder setStartTime(Date startTime) {
        this.startTime = DateUtil.DEFAULT_ON_SECOND_FORMAT.format(startTime);
        return this;
    }

    public FileMonitorBuilder setStartTime(LocalDateTime startTime) {
        this.startTime = startTime.format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
        return this;
    }

    public FileMonitorBuilder setEndTime(Date endTime) {
        this.endTime = DateUtil.DEFAULT_ON_SECOND_FORMAT.format(endTime);
        return this;
    }

    public FileMonitorBuilder setEndTime(LocalDateTime endTime) {
        this.endTime = endTime.format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
        return this;
    }

    public FileMonitorBuilder setExeTm(Integer exeTm) {
        this.exeTm = exeTm;
        return this;
    }

    public FileMonitorBuilder setExeStsSucc() {
        this.exeSts = "S";
        return this;
    }

    public FileMonitorBuilder setExeStsFail() {
        this.exeSts = "F";
        return this;
    }

    public FileMonitorBuilder setDescription(String description) {
        if (StringUtils.isNotBlank(description)) {
            if (description.length() >= 2000) {
                description = description.substring(0, 2000);
            }
        } else {
            description = null;
        }

        this.description = description;
        return this;
    }

    public FileMonitor build() {
        if (this.fileSize == null) {
            this.fileSize = 0L;
        }

        if (this.fileDataRow == null) {
            this.fileDataRow = 0L;
        }

        return new FileMonitor(this);
    }

    public String getFlowId() {
        return this.flowId;
    }

    public String getBizNo() {
        return this.bizNo;
    }

    public String getBizType() {
        return this.bizType;
    }

    public String getFileNo() {
        return this.fileNo;
    }

    public String getFileTitle() {
        return this.fileTitle;
    }

    public String getFileName() {
        return this.fileName;
    }

    public Long getFileSize() {
        return this.fileSize;
    }

    public Long getFileDataRow() {
        return this.fileDataRow;
    }

    public String getExeType() {
        return this.exeType;
    }

    public String getStartTime() {
        return this.startTime;
    }

    public String getEndTime() {
        return this.endTime;
    }

    public Integer getExeTm() {
        return this.exeTm;
    }

    public String getExeSts() {
        return this.exeSts;
    }

    public String getDescription() {
        return this.description;
    }
}
